package net.tavion.angelboot.framework.logger;

import org.slf4j.MDC;

/**
 * @author yuzhou
 * @date 2017/5/25
 * @time 7:55:52
 *
 */
public class MDCUtil {
    /**
     * The default MDC Key for logging
     */
    private static final String LOG_MDC_KEY = "requestId";
    /**
     * The default log MDC Value
     */
    private static final String LOG_MDC_DEFAULT = "UNKNOWN";

    /**
     * Setting MDC properties
     *
     * @param key   MDC Key
     * @param value MDC Value
     */
    public static void putMDCKey(String key, String value) {
        MDC.put(key, value != null ? value : LOG_MDC_DEFAULT);
    }

    /**
     * Set the MDC default Key attribute
     *
     * @param value MDC Value
     */
    public static void putMDCKey(String value) {
        putMDCKey(LOG_MDC_KEY, value);
    }

    /**
     * delete MDC Key
     *
     * @param key MDC Key
     */
    public static void removeMDCKey(String key) {
        MDC.remove(key);
    }

    /**
     * Remove the MDC default Key
     */
    public static void removeMDCKey() {
        removeMDCKey(LOG_MDC_KEY);
    }
}
